<template>
  <div>
    <div class="top_Dropdo">
      <li>
        <van-dropdown-menu> <van-dropdown-item v-model="value1" :options="option1" /></van-dropdown-menu>
      </li>
      <li>
        <van-dropdown-menu> <van-dropdown-item v-model="value2" :options="option2" /></van-dropdown-menu>
      </li>
    </div>
    <div>
      <div v-if="loading">Loading...</div>
      <!-- 判断状态为空时展示 -->
      <div v-else-if="false">
        <van-empty description="无可用数据">
          <van-button class="btn">健康科普</van-button>
          <van-button class="btn" @click="zhuan">咨询专家</van-button>
          <van-button class="btn" @click="gua">医院挂号</van-button>
          <van-button class="btn">线上购药</van-button>
          <span @click="feedback" class="feedback">我要反馈</span>
        </van-empty>
      </div>
      <!-- 数据不为空时展示 -->
      <div v-else>
        <div class="doction-box">
          <div v-for="(item, index) in doctlist" :key="index" class="doction-flex">
            <div class="doction-nav">
              <img src="../../assets/image/doctions.png" alt="" />
            </div>
            <div>
              <div>{{ item.nosocomium }}</div>
              <div class="doctions-node">
                <div>{{ item.socolv }}</div>
                <div>8:30放7天号源</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
// import axios from 'axios';
const value1 = ref(0);
const value2 = ref('a');
const value3 = ref('b');
const router = useRouter();
const data = ref([]);
const doctlist = ref([]);
const route = useRoute();
const items = ref(JSON.parse(route.query.items));
const SearchQuery = ref('');
import axios from '@/utils/axios/axios';
const loading = ref(true);
const doctionkeys = async () => {
  await axios.get('/api/doctionkey').then((res) => {
    SearchQuery.value = items.value;
    doctlist.value = res.data.res.filter((s) => s.nosocomium.includes(SearchQuery.value));
  });
};
doctionkeys();
// 判断是否存在后端数据如果有xaios传到前端
onMounted(async () => {
  try {
    // const response = await axios.get('https://api.example.com/data');
    // data.value = response.data;
  } catch (error) {
    console.error('Error fetching data:', error);
  } finally {
    loading.value = false;
  }
});
// 下拉表单
const option1 = [
  { text: '全部商品', value: 0 },
  { text: '新款商品', value: 1 },
  { text: '活动商品', value: 2 }
];
const option2 = [
  { text: '医院等级', value: 'a' },
  { text: '新款商品', value: 'b' },
  { text: '活动商品', value: 'c' }
];
const Xiang = () => {
  console.log(111);
};
// 咨询专家
const zhuan = () => {
  router.push('/layout/popular');
};
// 医院挂号
const gua = () => {
  router.push('/layout/appointment');
};
</script>

<style scoped lang="scss">
.list-item {
  width: 90%;
  height: 18vh;
  background: #d2e9eb;
  border-radius: 10px;
}

.btn {
  width: 80px;
  height: 30px;
  float: left;
  border: none;
  border: 1px solid blue;
  color: blue;
  border-radius: 10px;
  font-size: 12px;
  margin-left: 5px;
}

.feedback {
  color: blue;
  font-size: 14px;
  border-bottom: 2px solid blue;
  position: absolute;
  top: 80%;
  left: 42%;
}

.listTab2 {
  text-align: center;
}

.top_Dropdo {
  width: 100%;
  height: 8vh;
}

.top_Dropdo li {
  width: 30%;
  height: 100%;
  float: left;
  text-align: center;
  line-height: 8vh;
  margin-left: 9px;
  margin-left: 13vw;
}
.doction-box {
  width: 93%;
  margin: auto;
  height: 210px;
  background: #fff;
  margin-top: 10px;
  .nav-zong {
    font-size: 0.4rem;
    h4 {
      float: left;
      margin: 12px;
    }
    > div {
      float: right;
      margin: 12px;
    }
  }
  .doction-flex {
    display: flex;
    align-items: center;
    clear: both;
    .doctions-node {
      display: flex;
      align-items: center;
      > div:nth-child(1) {
        width: 55px;
        height: 20px;
        line-height: 20px;
        background: #dfebff;
        text-align: center;
        border-radius: 10px;
        overflow: hidden;
      }
      > div:nth-child(2) {
        color: #ccc;
      }
    }
    .doction-nav {
      clear: both;
      margin: 10px;
      width: 55px;
      text-align: center;
      border-radius: 4px;
      height: 50px;
      border: 1px solid #ccc;
    }
  }
}
</style>